package com.lly.songhigh.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.lly.songhigh.R;
import com.lly.songhigh.entity.SingerAlbum;


import java.util.List;


import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by 遇博 on 15/10/28.
 */
public class AlbumGridViewAdapter extends BaseAdapter {

    private Context context;
    private List<SingerAlbum.DataEntity> datas;

    public AlbumGridViewAdapter(Context context, List<SingerAlbum.DataEntity> datas) {
        this.context = context;
        this.datas = datas;
    }


    @Override
    public int getCount() {
        return datas != null && datas.size() > 0 ? datas.size() : 0;
    }

    @Override
    public SingerAlbum.DataEntity getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.singer_album_item, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.singer_album_item_title = (TextView) convertView
                    .findViewById(R.id.singer_album_item_title);
            viewHolder.singer_album_item_img = (ImageView) convertView
                    .findViewById(R.id.singer_album_item_img);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        SingerAlbum.DataEntity data = getItem(position);
        if (data != null) {
            viewHolder.singer_album_item_title.setText(data.getName());
            Picasso.with(context).load(data.getPicUrl()).placeholder(R.mipmap.placeholder_disk_300)
                    .error(R.mipmap.placeholder_disk_300).into(viewHolder.singer_album_item_img);
            return convertView;
        }
        return convertView;
    }

    class ViewHolder {
        public TextView singer_album_item_title;
        public ImageView singer_album_item_img;
    }
}




